﻿<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../font-awesome/css/font-awesome.css" rel="stylesheet" />
<link href="../js/plugins/layer/skin/layer.css" rel="stylesheet" />
<link href="../js/plugins/layer/skin/layer.ext.css" rel="stylesheet" />
<link href="../css/switchery/switchery.css" rel="stylesheet" />
<link href="../css/bootstrap.min.css" rel="stylesheet" />
<link href="../css/jqgrid/ui.jqgrid.css" rel="stylesheet" />
<link href="../css/style.min.css" rel="stylesheet" />
<script src="../js/jquery-2.1.1.min.js"></script>
<script src="../js/plugins/jqgrid/jquery.jqGrid.min.js"></script>
<script src="../js/plugins/jqgrid/i18n/grid.locale-cn.js"></script>
<script src="../js/plugins/layer/layer.min.js"></script>
<script src="../js/plugins/linq/linq.js"></script>
<script src="../weixin/js/common.js"></script>
<script src="../js/plugins/switchery/switchery.js"></script>
<script src="../js/inputControl.js"></script>
<style>
    .form-control {
        display: initial;
        width: auto;
        margin-right: 10px;
        padding: 0px;
        height:25px
    }

    .row {
        margin-top: 2px;
        margin-bottom: 2px;
    }

    .shijian {
        margin-top: 5px;
        padding-left: 0px !important;
    }

    .removeShop {
        margin-top: 30px
    }

    .cb {
        clear: both;
        border-left: 1px solid #dfdfdd;
    }

    .checkBoxTime {
        margin-left: 10px;
        position: relative;
        top: 2px;
    }

    .timeTitle {
        line-height: 22px;
        display: inline-block;
        position: relative;
        border-right: 1px solid #dfdfdd;
        border-bottom: 1px solid #dfdfdd;
        border-top: 1px solid #dfdfdd;
        padding-left: 10px;
        width: 56px;
        cursor: pointer;
        float: left;
    }

    .timeTitle .icon {
        font-size: 11px;
        position: absolute;
        right: 1px;
        bottom: 1px;
        display: none;
        color: #fff;
    }

    .timeTitle.check {
        background: linear-gradient(135deg, #fff 74%,#00a0e5 78%,#00a0e5 100%);
    }

    .timeTitle.check .icon {
        display: block;
    }

    .addShop, .addAllShop, .removeShop, .removeAllShop {
        cursor: pointer;
    }

    #leftTable th, #rightTable th {
        text-align: center;
    }

    #search-Provice, #search-City {
        width: 160px;
    }

    .taskList {
        cursor: pointer;
    }
    .container {
        display: block;
        position: relative;
        margin: 10px auto;
        width: 100%;
    }
    #taskTable td{
        padding: 5px;
        text-align: center;
    }
    #leftPart {
        border-right: 2px solid #dfdfdd;
    }
    .switchery{
    	height: 20px;
    	width: 40px;
    }
    .switchery > small{
    	height: 20px;
    	width: 20px;
    }
    .pull-right {
        margin-right:10px
    }
    #taskTable tr.check td{background: #dff0d8;}
</style>
<html>
<head>
    <title>任务设置</title>
    <style type="text/css">
    	html,body{
    		overflow: hidden;
    	}
    	.form-control{
    		display: inline-block;
    	}
    </style>
</head>
<body>
    <div class="container" style="margin-top: 5px">
        <div class="row clearfix">
            <div class="col-sm-2 column" id="leftPart">
                <div class="row clearfix" style="background-color:  #e7eaec;padding-top: 10px;padding-bottom: 6px;">
                    <label>任务列表:</label>
                </div>
                <div class="row clearfix">
                    <table id="taskTable" class="ui-common-table">
                        <tbody></tbody>
                    </table>
                </div>
            </div>
            <div class="col-sm-10 column" id="rightPart">
                <div class="row clearfix firstDiv" style="background-color:  #e7eaec;padding-top: 10px;padding-bottom: 4px;">
                    <div class="col-sm-9 column">
                        <label>任务明细:</label>
                    </div>
                    <div class="col-sm-3 column">
                        <button type="button" class="btn btn-sm btn-primary m-t-n-xs pull-right" id="save-Btn">保存</button>
                        <button type="button" class="btn btn-sm btn-primary m-t-n-xs pull-right" id="add-Btn">新增</button>
                        <%--<button type="button" class="btn btn-sm btn-danger m-t-n-xs pull-right" id="delete-Btn">删除</button>--%>
                    </div>
                </div>
                <div class="row clearfix secondDiv" style="margin-left:1px">
                    <div class="col-sm-5 column">
                        <div class="row">
                            <label>任务名称:</label>&nbsp&nbsp
                            <input id="taskName" type="text" data-projectcode="" class="form-control" style="width: 200px" />
                            <input id="taskID" type="hidden" hidden="hidden" />
                        </div>
                        <div class="row">
                            <label>任务类型:</label>&nbsp&nbsp
                            <select class="form-control" id="search-TaskType" style="width: 200px">
                            </select>
                        </div>
                        <div class="row">
                            <label>图片上限:</label>&nbsp&nbsp
                            <input id="picMax" type="number" data-projectcode="" class="form-control" min="1" max="9"/>
                            <label>张</label>
                        </div>
                        <div class="row" style="column-span: all">
                            <label>任务描述:</label>&nbsp&nbsp
                            <textarea rows="3" maxlength="200" id="desc" style="min-width: 180%; min-height: 60px; max-width: 180%; max-height: 60px"></textarea>
                        </div>
                    </div>
                    <div class="col-sm-7 column">
                        <div class="row">
                            <label>执行时间:</label>&nbsp&nbsp
                            <div class="shijian" style="display: initial">
                                <div class="cb" style="padding: 0 0 0 0px; overflow: hidden; display: inline-block;">
                                    <input type="checkbox" class="checkBoxTime hide" value="1" checked="checked" /><span class="timeTitle bl check">星期一<i class="fa fa-check icon"></i></span>
                                    <input type="checkbox" class="checkBoxTime hide" value="2" /><span class="timeTitle">星期二<i class="fa fa-check icon"></i></span>
                                    <input type="checkbox" class="checkBoxTime hide" value="3" /><span class="timeTitle">星期三<i class="fa fa-check icon"></i></span>
                                    <input type="checkbox" class="checkBoxTime hide" value="4" /><span class="timeTitle">星期四<i class="fa fa-check icon"></i></span>
                                    <input type="checkbox" class="checkBoxTime hide" value="5" /><span class="timeTitle">星期五<i class="fa fa-check icon"></i></span>
                                    <input type="checkbox" class="checkBoxTime hide" value="6" /><span class="timeTitle">星期六<i class="fa fa-check icon"></i></span>
                                    <input type="checkbox" class="checkBoxTime hide" value="7" /><span class="timeTitle">星期日<i class="fa fa-check icon"></i></span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <label>是否启用:</label>&nbsp&nbsp
                            <input type="checkbox" class="js-switch" id="isEnabled" checked />
                        </div>
                        <div class="row">
                            <label>必须完成:</label>&nbsp&nbsp
                            <input type="checkbox" class="js-switch" id="isMustFinish" checked />
                        </div>
                    </div>
                </div>
                <div class="row clearfix thridDiv">
                    <div class="col-sm-12 column">
                        <label>设置店铺权限:</label>
                    </div>
                </div>
                <div class="row clearfix fourthDiv">
                    <div class="col-sm-12 column">
                        <label>省:</label>&nbsp&nbsp
                        <select class="form-control" id="search-Provice">
                            <option value="">请选择</option>
                        </select>
                        <label>市:</label>&nbsp&nbsp
                        <select class="form-control" id="search-City">
                            <option value="">请选择</option>
                        </select>
                        <label>输入店铺:</label>&nbsp&nbsp
                        <input id="shopStr" type="text" data-projectcode="" class="form-control" />
                        <button type="button" class="btn btn-sm btn-primary m-t-n-xs" id="search-Btn">查询</button>
                    </div>
                </div>
                <div class="row clearfix fifthDiv" style="margin-top: 10px;">
                    <div class="col-sm-6 column jqGrid_wrapper">
                        <table id="leftTable">
                        </table>
                    </div>
                    <div class="col-sm-1 column" style="width: 20px;padding:0px;">
                        <div class="m-t-sm addShop"><i class="fa fa-angle-right fa-3x"></i></div>
                        <div class="addAllShop"><i class="fa fa-angle-double-right fa-3x"></i></div>
                        <div class="m-t-sm removeShop"><i class="fa fa-angle-left  fa-3x"></i></div>
                        <div class="removeAllShop"><i class="fa fa-angle-double-left fa-3x"></i></div>
                    </div>
                    <div class="col-sm-5 column jqGrid_wrapper">
                        <table id="rightTable">
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script>

    $(function () {

        $.jgrid.defaults.styleUI = "Bootstrap";

        $("#leftTable").jqGrid({
            datatype: "local",
            height: 500,
            autowidth: true,
            shrinkToFit: true,
            rowNum: -1,
            colNames: [" ", "店铺代码", "店铺名称", " ", "店铺代码", "店铺名称"],
            colModel: [
                {
                    name: "checkItem1",
                    index: "checkItem1",
                    width: 30,
                    align: "center",
                },
                {
                    name: "shopCode1",
                    index: "shopCode1",
                    width: 60,
                    align: "center",
                },
                {
                    name: "shopName1",
                    index: "shopName1",
                    width: 140,
                    align: "center",
                },
                {
                    name: "checkItem2",
                    index: "checkItem2",
                    width: 30,
                    align: "center",
                },
                {
                    name: "shopCode2",
                    index: "shopCode2",
                    width: 60,
                    align: "center",
                },
                {
                    name: "shopName2",
                    index: "shopName2",
                    width: 140,
                    align: "center",
                }],
            viewrecords: true,
            hidegrid: false
        });

        $("#rightTable").jqGrid({
            datatype: "local",
            height: 500,
            autowidth: true,
            shrinkToFit: true,
            rowNum: -1,
            colNames: [" ", "店铺代码", "店铺名称", " ", "店铺代码", "店铺名称"],
            colModel: [
                {
                    name: "checkItem1",
                    index: "checkItem1",
                    width: 30,
                    align: "center",
                },
                {
                    name: "shopCode1",
                    index: "shopCode1",
                    width: 70,
                    align: "center",
                },
                {
                    name: "shopName1",
                    index: "shopName1",
                    width: 140,
                    align: "center",
                },
                {
                    name: "checkItem2",
                    index: "checkItem2",
                    width: 30,
                    align: "center",
                },
                {
                    name: "shopCode2",
                    index: "shopCode2",
                    width: 70,
                    align: "center",
                },
                {
                    name: "shopName2",
                    index: "shopName2",
                    width: 140,
                    align: "center",
                }],
            viewrecords: true,
            hidegrid: false
        });

        var setTableWidth = function () {
            $("#taskTable").width($("#taskTable").parent().width());
            var height = $(".container").parents("html").height();
            $("#leftPart").height(height-10);
            $(".container .col-sm-11").height(height - 30);
            var rightHeight = $("#rightPart").height() -
                $(".firstDiv").height() -
                $(".secondDiv").height() -
                $(".thridDiv").height() -
                $(".fourthDiv").height() -
                50;
            $(".fifthDiv").height(rightHeight);
            $("#leftTable").setGridHeight(rightHeight);
            $("#rightTable").setGridHeight(rightHeight);
            $("#leftTable").setGridWidth($(".fifthDiv .col-sm-6").width());
            var rightWidth = $("#rightPart").width() -
                $(".fifthDiv .col-sm-6").width() -
                $(".fifthDiv .col-sm-1").width() - 20;
            $("#rightTable").setGridWidth(rightWidth);
        }

        setTableWidth();

        $(window).resize(function () {
            setTableWidth();
        });

        var addTableClass = function () {
            $("#leftTable").addClass("ui-common-table");
            $("#leftTable").addClass("table-bordered");
            $("#rightTable").addClass("ui-common-table");
            $("#rightTable").addClass("table-bordered");
            $(".ui-jqgrid-htable").addClass("ui-common-table");
            $(".ui-jqgrid-htable").addClass("table-bordered");
        }

        var isEnabledBtn = new Switchery($("#isEnabled")[0],
            {
                color: "#1AB394"
            });
        var isMustFinishBtn = new Switchery($("#isMustFinish")[0],
            {
                color: "#1AB394"
            });

        function setSwitchery(switchElement, checkedBool) {
            if ((checkedBool && !switchElement.isChecked()) || (!checkedBool && switchElement.isChecked())) {
                switchElement.setPosition(true);
                switchElement.handleOnchange(true);
            }
        }

        //星期
        $('.timeTitle').click(function () {
            $('.timeTitle').removeClass('check');
            $(this).addClass('check');
            $('.checkBoxTime').prop('checked', false);
            $('.checkBoxTime').eq($('.timeTitle').index(this)).click();
        });

        //添加 选中
        $(".addShop").on("click", function (event) {
            var e = window.event || event;
            if ($("#leftTable tr").length > 1) {
                var rightTable = $("#rightTable tbody");
                var checkList = $("#leftTable .checkItem:checked");
                var rightTDs = rightTable.find(".checkItem");
                var rightShopList = [];
                rightTDs.map(function (i, rightTD) {
                    var rightShop = {
                        "ShopCode": $(rightTD).attr("data-shopcode"),
                        "ShopName": $(rightTD).attr("data-shopname"),
                        "ShopID": $(rightTD).attr("data-shopid"),
                    }
                    rightShopList.push(rightShop);
                });
                if (rightTable[0].outerText == "没有数据") {
                    rightTable.empty();
                }
                checkList.map(function (i, item) {
                    var iShopCode = $(item).attr("data-shopcode");
                    if (rightShopList.Count == 0 ||
                        Enumerable.From(rightShopList).Where("d=>d.ShopCode=='" + iShopCode + "'").Count() == 0) {
                        var iShop = {
                            "ShopCode": $(item).attr("data-shopcode"),
                            "ShopName": $(item).attr("data-shopname"),
                            "ShopID": $(item).attr("data-shopid"),
                        }
                        rightShopList.push(iShop);
                    }
                });
                var length = rightShopList.length;
                var jsonData = [];
                var newData;
                rightShopList.map(function (rigthShop, i) {
                    if (i % 2 == 0) {
                        newData = {};
                        newData.checkItem1 = "<input type='checkbox' name='' data-shopid='" +
                            rigthShop.ShopID +
                            "' data-shopcode='" +
                            rigthShop.ShopCode +
                            "' data-shopname='" +
                            rigthShop.ShopName +
                            "' class='checkItem " +
                            rigthShop.ShopCode +
                            "'>";
                        newData.shopCode1 = rigthShop.ShopCode;
                        newData.shopName1 = rigthShop.ShopName;
                    };
                    if (i % 2 != 0) {
                        newData.checkItem2 = "<input type='checkbox' name='' data-shopid='" +
                            rigthShop.ShopID +
                            "' data-shopcode='" +
                            rigthShop.ShopCode +
                            "' data-shopname='" +
                            rigthShop.ShopName +
                            "' class='checkItem " +
                            rigthShop.ShopCode +
                            "'>";
                        newData.shopCode2 = rigthShop.ShopCode;
                        newData.shopName2 = rigthShop.ShopName;
                        jsonData.push(newData);
                    } else {
                        if (i == length - 1) {
                            jsonData.push(newData);
                        }
                    }
                });
                $("#rightTable").jqGrid('clearGridData');
                $("#rightTable").jqGrid('setGridParam', {
                    datatype: 'local',
                    data: jsonData,
                    rowNum: 999999999,
                }).trigger("reloadGrid");
                addTableClass();
            }
        });
        //添加 全部
        $(".addAllShop").on("click", function () {
            var e = window.event || event;
            if ($("#leftTable tr").length > 0) {
                var rightShopList = [];
                var leftList = $("#leftTable .checkItem");
                var rightTDs = $("#rightTable .checkItem");
                rightTDs.map(function (i, rightTD) {
                    var rightShop = {
                        "ShopCode": $(rightTD).attr("data-shopcode"),
                        "ShopName": $(rightTD).attr("data-shopname"),
                        "ShopID": $(rightTD).attr("data-shopid"),
                    }
                    rightShopList.push(rightShop);
                });
                leftList.map(function (i, leftItem) {
                    var iShopCode = $(leftItem).attr("data-shopcode");
                    if (rightShopList.Count == 0 ||
                        Enumerable.From(rightShopList).Where("d=>d.ShopCode=='" + iShopCode + "'").Count() == 0) {
                        var iShop = {
                            "ShopCode": $(leftItem).attr("data-shopcode"),
                            "ShopName": $(leftItem).attr("data-shopname"),
                            "ShopID": $(leftItem).attr("data-shopid"),
                        }
                        rightShopList.push(iShop);
                    }
                });
                var jsonData = [];
                var newData;
                var length = rightShopList.length;
                rightShopList.map(function (rightShop,i) {
                    if (i % 2 == 0) {
                        newData = {};
                        newData.checkItem1 = "<input type='checkbox' name='' data-shopid='" +
                            rightShop.ShopID +
                            "' data-shopcode='" +
                            rightShop.ShopCode +
                            "' data-shopname='" +
                            rightShop.ShopName +
                            "' class='checkItem " +
                            rightShop.ShopCode +
                            "'>";
                        newData.shopCode1 = rightShop.ShopCode;
                        newData.shopName1 = rightShop.ShopName;
                    };
                    if (i % 2 != 0) {
                        newData.checkItem2 = "<input type='checkbox' name='' data-shopid='" +
                            rightShop.ShopID +
                            "' data-shopcode='" +
                            rightShop.ShopCode +
                            "' data-shopname='" +
                            rightShop.ShopName +
                            "' class='checkItem " +
                            rightShop.ShopCode +
                            "'>";
                        newData.shopCode2 = rightShop.ShopCode;
                        newData.shopName2 = rightShop.ShopName;
                        jsonData.push(newData);
                    } else {
                        if (i == length - 1) {
                            jsonData.push(newData);
                        }
                    }
                });
                $("#rightTable").jqGrid('clearGridData');
                $("#rightTable").jqGrid('setGridParam', {
                    datatype: 'local',
                    data: jsonData,
                    rowNum: 999999999,
                }).trigger("reloadGrid");
                addTableClass();
            }
        });
        //删除 选中
        $(".removeShop").on("click", function (event) {
            var e = window.event || event;
            var uncheckList = [];
            var rightTDs = $("#rightTable .checkItem").not("input:checked");
            rightTDs.map(function (i, rightTD) {
                var rightShop = {
                    "ShopCode": $(rightTD).attr("data-shopcode"),
                    "ShopName": $(rightTD).attr("data-shopname"),
                    "ShopID": $(rightTD).attr("data-shopid"),
                }
                uncheckList.push(rightShop);
            });
            var jsonData = [];
            var newData;
            var length = uncheckList.length;
            uncheckList.map(function (rightShop,i) {
                if (i % 2 == 0) {
                    newData = {};
                    newData.checkItem1 = "<input type='checkbox' name='' data-shopid='" +
                        rightShop.ShopID +
                        "' data-shopcode='" +
                        rightShop.ShopCode +
                        "' data-shopname='" +
                        rightShop.ShopName +
                        "' class='checkItem " +
                        rightShop.ShopCode +
                        "'>";
                    newData.shopCode1 = rightShop.ShopCode;
                    newData.shopName1 = rightShop.ShopName;
                };
                if (i % 2 != 0) {
                    newData.checkItem2 = "<input type='checkbox' name='' data-shopid='" +
                        rightShop.ShopID +
                        "' data-shopcode='" +
                        rightShop.ShopCode +
                        "' data-shopname='" +
                        rightShop.ShopName +
                        "' class='checkItem " +
                        rightShop.ShopCode +
                        "'>";
                    newData.shopCode2 = rightShop.ShopCode;
                    newData.shopName2 = rightShop.ShopName;
                    jsonData.push(newData);
                } else {
                    if (i == length - 1) {
                        jsonData.push(newData);
                    }
                }
            });
            $("#rightTable").jqGrid('clearGridData');
            $("#rightTable").jqGrid('setGridParam', {
                datatype: 'local',
                data: jsonData,
                rowNum: 999999999,
            }).trigger("reloadGrid");
            addTableClass();
        });
        //删除 全部
        $(".removeAllShop").on("click", function () {
            var e = window.event || event;
            $("#rightTable").jqGrid('clearGridData');
        });

        var loadTaskTypeList = function () {
            var s = layer.load(0,
                {
                    shade: [0.2, '#fff'] //0.1透明度的白色背景
                });
            var sTaskType = $("#search-TaskType");
            $.getJSON("TaskType.json", function (data) {
                var tHtml = "";
                data.Task.map(function(item) {
                    tHtml += '<option value=' + item.Value + '>' + item.TaskType + '</option>';
                });
                sTaskType.append(tHtml);
                layer.close(s);
            });
        }

        loadTaskTypeList();

        var loadTaskList = function () {
            var s = layer.load(0,
                {
                    shade: [0.2, '#fff'] //0.1透明度的白色背景
                });
            $.post("TaskHandler.ashx",
                {
                    "action": "GetTaskList",
                },
                function (data) {
                    var taskTable = $("#taskTable tbody");
                    if (data.Success == true) {
                        var tHtml = "";
                        data.Data.map(function (item, i) {
                            tHtml += "<tr><td style='font-size:12px' class='taskList " +
                                item.TaskID +
                                "' data-taskid='" +
                                item.TaskID +
                                "'>" +
                                item.TaskName +
                                "</td></tr>";
                        });
                        taskTable.empty();
                        taskTable.append(tHtml);
                    } else {
                        var emptyTable = "<tr><td colspan='6'>没有数据</td></tr>";
                        taskTable.empty();
                        taskTable.append(emptyTable);
                    }
                    layer.close(s);
                });
        }

        loadTaskList();

        var proviceName = "";
        var cityName = "";
        var shopStr = "";
        //加载店铺；列表
        var loadShopList = function () {
            var s = layer.load(0,
                {
                    shade: [0.2, '#fff'] //0.1透明度的白色背景
                });
            $.post("TaskHandler.ashx",
                {
                    "action": "GetShopList",
                    "bigAreaName": proviceName,
                    "areaName": cityName,
                    "shopStr": shopStr,
                },
                function (data) {
                    if (data.Success == true) {
                        $("#leftTable").jqGrid('clearGridData');
                        var length = data.Data.length;
                        if (length > 0) {
                            var jsonData = [];
                            var newData;
                            data.Data.map(function (item, i) {
                                if (i % 2 == 0) {
                                    newData = {};
                                    newData.checkItem1 = "<input type='checkbox' name='' data-shopid='" +
                                        item.ShopID +
                                        "' data-shopcode='" +
                                        item.ShopCode +
                                        "' data-shopname='" +
                                        item.ShopName +
                                        "' class='checkItem " +
                                        item.ShopCode +
                                        "'>";
                                    newData.shopCode1 = item.ShopCode;
                                    newData.shopName1 = item.ShopName;
                                };
                                if (i % 2 != 0) {
                                    newData.checkItem2 = "<input type='checkbox' name='' data-shopid='" +
                                        item.ShopID +
                                        "' data-shopcode='" +
                                        item.ShopCode +
                                        "' data-shopname='" +
                                        item.ShopName +
                                        "' class='checkItem " +
                                        item.ShopCode +
                                        "'>";
                                    newData.shopCode2 = item.ShopCode;
                                    newData.shopName2 = item.ShopName;
                                    jsonData.push(newData);
                                } else {
                                    if (i == length - 1) {
                                        jsonData.push(newData);
                                    }
                                }
                            });
                            $("#leftTable").jqGrid('setGridParam', {
                                datatype: 'local',
                                data: jsonData,
                                rowNum: 999999999,
                            }).trigger("reloadGrid");
                            addTableClass();
                        }
                    }
                    layer.close(s);
                });
        }

        loadShopList();

        var areaJson = {};
        //加载地区
        var loadAreaList = function () {
            var s = layer.load(0,
                {
                    shade: [0.2, '#fff'] //0.1透明度的白色背景
                });
            $.post("TaskHandler.ashx",
                {
                    "action": "GetAreaList",
                },
                function (data) {
                    var sProvice = $("#search-Provice");
                    if (data.Success == true) {
                        var sHtml = "";
                        areaJson = data.Data;
                        data.Data.map(function (item, i) {
                            sHtml += '<option value=' + item.AreaID + '>' + item.AreaName + '</option>';
                        });
                        sProvice.append(sHtml);
                    }
                    layer.close(s);
                });
        }
        loadAreaList();

        $("#search-Provice").change(function () {
            var sCity = $("#search-City");
            var areaID = $(this).children('option:selected').val();
            var childrenList = Enumerable.From(areaJson).Where("d=>d.AreaID=='" + areaID + "'").First();
            var cHtml = "<option value=''>请选择</option>";
            childrenList.child.map(function (child, i) {
                cHtml += '<option value=' + child.AreaID + '>' + child.AreaName + '</option>';
            });
            sCity.empty();
            sCity.append(cHtml);
        });
        //查询
        $("#search-Btn").on("click", function () {
            var e = window.event || event;
            proviceName = $("#search-Provice").find("option:selected").text();
            cityName = $("#search-City").find("option:selected").text();
            shopStr = $("#shopStr").val();
            if (proviceName == "请选择") {
                proviceName = "";
            }
            if (cityName == "请选择") {
                cityName = "";
            }
            loadShopList();
        });

        //删除
        $("#delete-Btn").on("click", function () {
            var e = window.event || event;
            var taskID = $("#taskID").val();
            if (taskID != "") {
                var s = layer.load(0,
                    {
                        shade: [0.2, '#fff'] //0.1透明度的白色背景
                    });
                $.post("TaskHandler.ashx",
                    {
                        "action": "DeleteTask",
                        "taskID": taskID,
                    },
                    function (data) {
                        if (data.Success == true) {
                            loadTaskList();
                            $("#add-Btn").click();
                            layer.alert('删除成功！',
                                {
                                    icon: 1,
                                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                                });
                        } else {
                            layer.alert(data.Message,
                                {
                                    icon: 1,
                                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                                });
                        }
                        layer.close(s);
                    });
            }
        });

        //新增
        $("#add-Btn").on("click", function () {
            var e = window.event || event;
            proviceName = "";
            cityName = "";
            shopStr = "";
            $("#taskID").val("");
            $("#taskName").val("");
            $("#search-TaskType").val("");
            $("#picMax").val("");
            $("#desc").val("");
            loadShopList();
            loadAreaList();
            $(".removeAllShop").click();
        });

        //保存
        $("#save-Btn").on("click", function () {
            var e = window.event || event;
            var taskID = $("#taskID").val();
            var taskName = $("#taskName").val();
            var taskType = $("#search-TaskType").val();
            var picMax = $("#picMax").val();
            var desc = $("#desc").val();
            var execWeek = $('.checkBoxTime:checked').val();
            var checkList = $("#rightTable .checkItem");
            var isEnabled = $("#isEnabled")[0].checked;
            var isMustFinish = $("#isMustFinish")[0].checked;
            var shopList = [];
            if (Y.checkNull(taskName)) {
                layer.alert('请输入任务名称',
                    {
                        icon: 1,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                    });
                return false;
            }
            if (taskName.length>10) {
                layer.alert('任务名称过长',
                    {
                        icon: 1,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                    });
                return false;
            }
            if (Y.checkNull(picMax)) {
                layer.alert('请输入图片上限',
                    {
                        icon: 1,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                    });
                return false;
            }
            if (checkList.length <= 0) {
                layer.alert('请选择店铺!',
                    {
                        icon: 1,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                    });
                return false;
            }
            checkList.map(function (i, item) {
                var shopID = $(item).attr("data-shopid");
                shopList.push(shopID);
            });
            var s = layer.load(0,
                {
                    shade: [0.2, '#fff'] //0.1透明度的白色背景
                });
            $.post("TaskHandler.ashx",
                {
                    "action": "SaveTask",
                    "taskID": taskID,
                    "taskName": taskName,
                    "taskType": taskType,
                    "picMax": picMax,
                    "desc": desc,
                    "execWeek": execWeek,
                    "isEnabled": isEnabled,
                    "isMustFinish": isMustFinish,
                    "UserID": window.localStorage.getItem("UserID"),
                    "shopList": JSON.stringify(shopList),
                },
                function (data) {
                    if (data.Success == true) {
                        loadTaskList();
                        $("#add-Btn").click();
                        layer.alert('保存成功',
                            {
                                icon: 1,
                                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                            });
                    } else {
                        layer.alert(data.Message,
                            {
                                icon: 1,
                                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                            });
                    }
                    layer.close(s);
                });
        });

        $("#leftPart").on("click", ".taskList", function () {
            $(this).parents('#leftPart').find('tr').removeClass('check');
            $(this).parents('tr').addClass('check');
            var taskID = $(this).attr("data-taskid");
            var s = layer.load(0,
                {
                    shade: [0.2, '#fff'] //0.1透明度的白色背景
                });
            $.post("TaskHandler.ashx",
                {
                    "action": "GetTask",
                    "taskID": taskID,
                },
                function (data) {
                    if (data.Success == true) {
                        $("#rightTable").jqGrid('clearGridData');
                        $("#add-Btn").click();
                        $("#taskID").val(data.Data.TaskID);
                        $("#taskName").val(data.Data.TaskName);
                        $("#search-TaskType").val(data.Data.TaskType);
                        $("#picMax").val(data.Data.ImgCount);
                        $("#desc").val(data.Data.TaskDescribe);
                        $('.timeTitle').eq(data.Data.ExecWeek - 1).click();//执行时间
                        if (data.Data.IsEnabled) {
                            setSwitchery(isEnabledBtn, true);
                        } else {
                            setSwitchery(isEnabledBtn, false);
                        }
                        if (data.Data.IsMustFinish) {
                            setSwitchery(isMustFinishBtn, true);
                        } else {
                            setSwitchery(isMustFinishBtn, false);
                        }
                        var jsonData = [];
                        var newData;
                        var length = data.Data.shopList.length;
                        data.Data.shopList.map(function (item, i) {
                            if (i % 2 == 0) {
                                newData = {};
                                newData.checkItem1 = "<input type='checkbox' name='' data-shopid='" +
                                    item.ShopID +
                                    "' data-shopcode='" +
                                    item.ShopCode +
                                    "' data-shopname='" +
                                    item.ShopName +
                                    "' class='checkItem " +
                                    item.ShopCode +
                                    "'>";
                                newData.shopCode1 = item.ShopCode;
                                newData.shopName1 = item.ShopName;
                            };
                            if (i % 2 != 0) {
                                newData.checkItem2 = "<input type='checkbox' name='' data-shopid='" +
                                    item.ShopID +
                                    "' data-shopcode='" +
                                    item.ShopCode +
                                    "' data-shopname='" +
                                    item.ShopName +
                                    "' class='checkItem " +
                                    item.ShopCode +
                                    "'>";
                                newData.shopCode2 = item.ShopCode;
                                newData.shopName2 = item.ShopName;
                                jsonData.push(newData);
                            } else {
                                if (i == length - 1) {
                                    jsonData.push(newData);
                                }
                            }
                        });
                        $("#rightTable").jqGrid('setGridParam', {
                            datatype: 'local',
                            data: jsonData,
                            rowNum: 999999999,
                        }).trigger("reloadGrid");
                        addTableClass();
                    } else {
                        console.log(data);
                    }
                    layer.close(s);
                });
        });

        //限制确认标准金额百分比
        inputControl.init({
            els: ['#picMax'],
            container: '.row',
            inputEvent: 'keyup',
            defValue: '',
            min: 0,
            max:9,
            isNum: true,
            tranInt: true,	
            inputLength: 5,
            callback: function (value, el, event) {
                //checkAmountRate(el.attr('data-sign'));
            }
        });
    });

</script>
